package cn.neusoft.service.impl;

import cn.neusoft.po.Employee;
import cn.neusoft.mapper.EmployeeMapper;
import cn.neusoft.query.EmployeeQuery;
import cn.neusoft.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hxj
 * @since 2023-12-19
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Override
    public Page<Employee> getByPage(EmployeeQuery query) {
        //存放搜索条件
        QueryWrapper<Employee> queryWrapper = Wrappers.query(new Employee())
         //StringUtils.hasText(query.getUsername())  StringUtils字符串工具类  判断变量是否有值
         //三个参数：该条件加不加 boolean值 ,  比对的字段名称(跟数据库一致) ,   比对的值
        .like(StringUtils.hasText(query.getUsername()),"username",query.getUsername())
        .like(StringUtils.hasText(query.getEmail()),"email",query.getEmail())
        .eq(StringUtils.hasText(query.getPhone()),"phone",query.getPhone())
                .orderByDesc("id");

        //存放分页条件
        Page pageQuery = new Page(query.getCurrent(),query.getSize());

        //自定义分页时  准备好分页条件Page  准备好搜索条件Wrapper
        Page<Employee> departmentIPage = baseMapper.selectJoinDept(pageQuery, queryWrapper);
        return departmentIPage;
    }
}
